package edu.ChildrensBooks.model



import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Book)
class BookTests {

    void testValidation() {
		Book book = new Book("This is a title", "Russell Gillen", null, "blah", -5, 5, "en", "Math skills")
		book.validate()
		assertEquals book.errors.errorCount, 2
		
		book = new Book(null, "Author", null, null, 0, 1, "en", "Math skills")
		book.validate()
		assertEquals book.errors.errorCount, 1
		
		book = new Book("Title", null, null, null, 0, 1, null, "Math skills")
		book.validate()
		assertEquals book.errors.errorCount, 1
		
		book = new Book("Title", "Author", null, null, 5, 3, "en", "Math skills")
		book.validate()
		assertEquals book.errors.errorCount, 2
		
		book = new Book("Title", "Author", null, null, 0, 1, "en", "no skills")
		book.validate()
		assertEquals book.errors.errorCount, 1
		
		book = new Book(null, null, null, null, 5, 4, null, null)
		book.validate()
		assertEquals book.errors.errorCount, 5
		
		book = new Book("Title", "Author", null, null, 1, 2, null, "Math skills")
		book.validate()
		assertEquals book.errors.errorCount, 0
		
		book = new Book("Title", "Author", null, "blahblah", 1, 2, null, "Math skills")
		book.validate()
		assertEquals book.errors.errorCount, 1
		
		book = new Book("Title", "Author", null, "978-3-16-148410-0", 1, 2, null, "Math skills")
		book.validate()
		assertEquals book.errors.errorCount, 0
	}
}
